﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Xml;
using System.Xml.Serialization;
using System.IO;

using ecdl.demo.persistence;
using Ninject;

namespace ecdl.demo.model.file {
    public class FileTaskCatalogue : ITaskProvider {

        private static readonly string DEFAULT_XML = "ecdl.demo.file.res.FileTaskCatalogue.xml";

        private static System.IO.Stream OpenDefaultFile() {
            System.IO.Stream stream = typeof(FileTaskCatalogue).Assembly.GetManifestResourceStream(DEFAULT_XML);
            return stream;
        }

        public static FileTaskCatalogue GetDefaultCatalogue() {
            FileTaskSerializer serializer = new FileTaskSerializer();
            
            FileTaskCatalogue questionaire = (FileTaskCatalogue)serializer.Deserialize(new StreamReader(OpenDefaultFile()));
            return questionaire;
        }

        public FileTaskCatalogue() {
            FileTasks = new List<FileTaskDTO>();
        }

        [XmlElement("FileTask")]
        public List<FileTaskDTO> FileTasks { get; set; }

        public IEnumerable<ITask> GetTasks(ModelFactory factory) {
            List<ITask> tasks = new List<ITask>();
            foreach (var item in FileTasks) {
                tasks.Add(item.ToModel(factory));
            }
            return tasks;
        }
    }
}
